package com.newworld.dmsapp2.activity.history;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONObject;

import android.content.Intent;
import android.graphics.Paint;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.newworld.dmsapp2.BaseActivity;
import com.newworld.dmsapp2.R;
import com.newworld.dmsapp2.activity.HistorySearchActivity;
import com.newworld.dmsapp2.activity.ServiceScheduleActivity;
import com.newworld.dmsapp2.activity.ToDoTaskListActivity;
import com.newworld.dmsapp2.activity.UploadService;
import com.newworld.dmsapp2.bean.RepairNode;
import com.newworld.dmsapp2.bean.Task;
import com.newworld.dmsapp2.bean.User;
import com.newworld.dmsapp2.fragment.bean.HistortyDetail;
import com.newworld.dmsapp2.util.Config;
import com.newworld.dmsapp2.util.HttpUtil;
import com.newworld.dmsapp2.util.SingleSample;
import com.newworld.dmsapp2.util.Tool;

public class HistorySearchTimeLineActivity extends BaseActivity {

	private ListView listView;
	private TimelineAdapter timelineAdapter;
	private TextView hdtasknumberTv, hdhouseadressTv, hdreporternameTv,
			hdreporterphoneTv, hdareaTv;
	private User user;
	private String repairId;
	private Intent intent;
	private Bundle bundle;
	private Task task = new Task();
	private List<RepairNode> repairNodes = new ArrayList<RepairNode>();
	private HistortyDetail hd;
	private static List<HistortyDetail> historydetaillist = new ArrayList<HistortyDetail>();
	private ProgressBar loginbar;
	private String areaname;
	private String houseadress;
	private String areatype;


	Handler mHandler = new Handler() {
		@Override
		public void handleMessage(android.os.Message msg) {
			switch (msg.what) {

			case Config.HANDLER_MSG_GETDATA_SUCCESS:
				
				/*boolean pdyflag = (null != user
						.getFunctionlistFromUser(Config.FUNCTION_REAL_HISTORYLIST_DISPATCHER) 
						&& null != user.getFunctionlistFromUser(Config.FUNCTION_REAL_HISTORYLIST_DISPATCHER).get(0));//判断是否是派单员
*/	
				boolean hostflag = ((null != user
				.getFunctionlistFromUser(Config.FUNCTION_REAL_HISTORYLIST_OWNER) 
				&& null != user.getFunctionlistFromUser(Config.FUNCTION_REAL_HISTORYLIST_OWNER).get(0))
				||(null != user
				.getFunctionlistFromUser(Config.FUNCTION_REAL_HISTORYLIST_NONOWENER) 
				&& null != user.getFunctionlistFromUser(Config.FUNCTION_REAL_HISTORYLIST_NONOWENER).get(0)));//判断是否是业主
				hdtasknumberTv.setText(task.getRepairNum());
				hdhouseadressTv.setText(houseadress);
				hdreporternameTv.setText(task.getReporter_realName());
				hdreporterphoneTv.setText(task.getReporter_phone());
				// 维修区域信息拼接
				/*if(null != areatype){
					if (areatype.equals(Config.AREACODE_INDOOR)) {
						areaname = Config.AREANAME_INDOOR;
					} else {
						areaname = Config.AREANAME_PUBLIC;
					}
				} else*/ 
				if(null != task.getHouse_houseType_typeCode()){
					if (task.getHouse_houseType_typeCode().equals(Config.AREACODE_INDOOR)) {
						areaname = Config.AREANAME_INDOOR;
					}else if (task.getHouse_houseType_typeCode().equals(Config.AREACODE_BUSINESS)) {
						areaname = Config.AREANAME_BUSINESS;
					}else {
						areaname = Config.AREANAME_PUBLIC;
					}
				}
				hdareaTv.setText(areaname + "/" + task.getRepairObject());
				String aaa= areaname + "/" + task.getRepairObject();
				Log.e(aaa,aaa);
				historydetaillist.clear();
				if(!hostflag){
					for(RepairNode r:repairNodes){
						hd = new HistortyDetail();
						if (r.getNodeTime().length() > Config.TIMELENGTH) {
							hd.setDetail1_content(r.getNodeTime().substring(0,
									Config.TIMELENGTH));
						} else {
							hd.setDetail1_content(r.getNodeTime());
						}
						if(r.getNodeType_typeCode().equals(Config.TYPECODE_REPORT)){//提单
							hd.setDetail1("报修时间 ");
							hd.setDetail2("问题描述");
							hd.setDetail2_content(task.getProblemDescript());
							hd.setDetail6("图片留言");
							hd.setDetail6_image1(task.getProblemImage1());
							hd.setDetail6_image2(task.getProblemImage2());
							hd.setDetail6_voice(task.getProblemVoice());

							if (null != task.getProblemVoice()
									&& !task.getProblemVoice().equals("")) {
								int voicetime = Tool.voiceTime(HistorySearchTimeLineActivity.this,Config.VOICE_PATH+task.getProblemVoice());
								int realvoicetime = (int) voicetime/1000;
								Log.e("realvoicetime", realvoicetime+"'");
								hd.setDetail6_voicetime(realvoicetime+"'");
								Log.e("realvoicetime提单1", hd.getDetail6_voicetime());
							}else{
								
							}
							historydetaillist.add(hd);
						}else if(r.getNodeType_typeCode().equals(Config.TYPECODE_DISPATCH)){//分配
							hd.setDetail1("派单时间 ");
							hd.setDetail2("派单人员");
							hd.setDetail2_content(r.getOperator_realName());
							hd.setDetail2_content2(r.getOperator_mobilePhone());
							historydetaillist.add(hd);
						}else if(r.getNodeType_typeCode().equals(Config.TYPECODE_REDISPATCH)
								||r.getNodeType_typeCode().equals(Config.TYPECODE_COMPELETEREDISPATCH)){//派单员改派
							if (true) {// 派单员完成改派
							hd.setDetail1("改派时间 ");
							hd.setDetail2("派单人员");
							hd.setDetail2_content(r.getOperator_realName());
							hd.setDetail2_content2(r.getOperator_mobilePhone());
							historydetaillist.add(hd);
							}
						}else if(r.getNodeType_typeCode().equals(Config.TYPECODE_MANAGERCOMPELETEREDISPATCH)){//部门主管改派
							if (true) {// 主管完成改派
							hd.setDetail1("改派时间 ");
							hd.setDetail2("派单人员");
							hd.setDetail2_content(r.getOperator_realName());
							hd.setDetail2_content2(r.getOperator_mobilePhone());
							historydetaillist.add(hd);
							}
						}else if(r.getNodeType_typeCode().equals(Config.TYPECODE_MANAGERAROMD)
								||r.getNodeType_typeCode().equals(Config.TYPECODE_MANAGERPROG)
								||r.getNodeType_typeCode().equals(Config.TYPECODE_MANAGERAROS)){//部门主管申请改派
							if (true) {// 派单员
							hd.setDetail1("申请改派 ");
							hd.setDetail2("部门主管");
							hd.setDetail2_content(r.getOperator_realName());
							hd.setDetail2_content2(r.getOperator_mobilePhone());
							historydetaillist.add(hd);
							}
						}else if(r.getNodeType_typeCode().equals(Config.TYPECODE_SERVERAROG)
								||r.getNodeType_typeCode().equals(Config.TYPECODE_SERVERAROS)){//维修人员申请改派
							if (true) {// 派单员
							hd.setDetail1("申请改派 ");
							hd.setDetail2("维修人员");
							hd.setDetail2_content(r.getOperator_realName());
							hd.setDetail2_content2(r.getOperator_mobilePhone());
							historydetaillist.add(hd);
							}
						}else if(r.getNodeType_typeCode().equals(Config.TYPECODE_RECEIVEORDER)){//接单
							hd.setDetail1("接单时间 ");
							hd.setDetail2("维修人员");
							hd.setDetail2_content(r.getOperator_realName());
							hd.setDetail2_content2(r.getOperator_mobilePhone());
							historydetaillist.add(hd);
						}else if(r.getNodeType_typeCode().equals(Config.TYPECODE_SERVE)){//维修、完成
							hd.setDetail1("完成时间 ");
							if (task.getFinishTime().length() > Config.TIMELENGTH) {
								hd.setDetail1_content(task.getFinishTime().substring(0,
										Config.TIMELENGTH));
							} else {
								hd.setDetail1_content(task.getFinishTime());
							}
							hd.setDetail2("评价描述");
							hd.setDetail2_content(task.getEvaluateDescript());
							hd.setDetail3("综合评价");
							hd.setDetail3_content(task.getAverageStar());
							hd.setDetail4("上门时间 ");
							if (task.getRepairTime().length() > Config.TIMELENGTH) {
								hd.setDetail4_content(task.getRepairTime().substring(0,
										Config.TIMELENGTH));
							} else {
								hd.setDetail4_content(task.getRepairTime());
							}
							hd.setDetail5("维修记录");
					 		hd.setDetail5_content(task.getSolvedDescript());
							hd.setDetail6("图片留言");
							hd.setDetail6_image1(task.getSolvedImage1());
							hd.setDetail6_image2(task.getSolvedImage2());
							hd.setDetail6_voice(task.getSolvedVoice());
							if (null != task.getSolvedVoice()
									&& !task.getSolvedVoice().equals("")) {
								int voicetime = Tool.voiceTime(HistorySearchTimeLineActivity.this,Config.VOICE_PATH+task.getSolvedVoice());
								int realvoicetime = (int) voicetime/1000;
								
								Log.e("realvoicetime完成1", realvoicetime+"'");
								hd.setDetail6_voicetime(realvoicetime+"'");
								Log.e("realvoicetime完成2--节点", hd.getDetail6_voicetime());
							}else{
								
							}
							historydetaillist.add(hd);
						}else if(r.getNodeType_typeCode().equals(Config.TYPECODE_REVISIT)){//回访
							hd.setDetail1("回访时间");
							hd.setDetail2("回访记录");
							hd.setDetail2_content(task.getVisitRecord());
							historydetaillist.add(hd);
						}else if(r.getNodeType_typeCode().equals(Config.TYPECODE_PMStop)){//终止回访
							hd.setDetail1("终止时间");
							if (task.getVisitTerminateTime().length() > Config.TIMELENGTH) {
								hd.setDetail1_content(task.getVisitTerminateTime().substring(0,
										Config.TIMELENGTH));
							} else {
								hd.setDetail1_content(task.getVisitTerminateTime());
							}
							hd.setDetail2("项目经理");
							hd.setDetail2_content(task.getVisitTerminator_realName());
							hd.setDetail2_content2(task.getVisitTerminator_mobilePhone());
							//hd.setDetail5("终止描述");
							if(null!=task.getVisitTerminateNote()&&!task.getVisitTerminateNote().equals("")){
								Log.e("终止记录1是："+task.getVisitTerminateNote(), task.getVisitTerminateNote());
							}
							hd.setDetail5_content(task.getVisitTerminateNote());
							
							Log.e("终止记录2是："+hd.getDetail5_content(), hd.getDetail5_content());
						
							historydetaillist.add(hd);
						}
					}
				}else{
					
						if (null != task.getVisitTime()
								&& !task.getVisitTime().equals("")) {
							hd = new HistortyDetail();
							hd.setDetail1("回访时间");
							if (task.getVisitTime().length() > Config.TIMELENGTH) {
								hd.setDetail1_content(task.getVisitTime()
										.substring(0, Config.TIMELENGTH));
							} else {
								hd.setDetail1_content(task.getVisitTime());
							}

							hd.setDetail2("回访记录");
							hd.setDetail2_content(task.getVisitRecord());
							historydetaillist.add(hd);
						}

					hd = new HistortyDetail();
					hd.setDetail1("完成时间 ");
					if (task.getFinishTime().length() > Config.TIMELENGTH) {
						hd.setDetail1_content(task.getFinishTime().substring(0,
								Config.TIMELENGTH));
					} else {
						hd.setDetail1_content(task.getFinishTime());
					}
					hd.setDetail2("评价描述");
					hd.setDetail2_content(task.getEvaluateDescript());
					hd.setDetail3("综合评价");
					hd.setDetail3_content(task.getAverageStar());
					hd.setDetail4("上门时间 ");
					if (task.getRepairTime().length() > Config.TIMELENGTH) {
						hd.setDetail4_content(task.getRepairTime().substring(0,
								Config.TIMELENGTH));
					} else {
						hd.setDetail4_content(task.getRepairTime());
					}
					hd.setDetail5("维修记录");
					hd.setDetail5_content(task.getSolvedDescript());
					hd.setDetail6("图片留言");
					hd.setDetail6_image1(task.getSolvedImage1());
					hd.setDetail6_image2(task.getSolvedImage2());
					hd.setDetail6_voice(task.getSolvedVoice());
					if (null != task.getSolvedVoice()
							&& !task.getSolvedVoice().equals("")) {
						int voicetime = Tool.voiceTime(HistorySearchTimeLineActivity.this,Config.VOICE_PATH+task.getSolvedVoice());
						int realvoicetime = (int) voicetime/1000;
						Log.e("realvoicetime hz完成1", realvoicetime+"'");
						hd.setDetail6_voicetime(realvoicetime+"'");
						Log.e("realvoicetime hz完成2", hd.getDetail6_voicetime());
					}else{
					}
					historydetaillist.add(hd);

					hd = new HistortyDetail();
					hd.setDetail1("派单时间 ");
					if (task.getDispatchTime().length() > Config.TIMELENGTH) {
						hd.setDetail1_content(task.getDispatchTime().substring(0,
								Config.TIMELENGTH));
					} else {
						hd.setDetail1_content(task.getDispatchTime());
					}
					hd.setDetail2("维修人员");
					hd.setDetail2_content(task.getServer_realName());
					hd.setDetail2_content2(task.getServer_mobilePhone());
					historydetaillist.add(hd);

					/*hd = new HistortyDetail();
					hd.setDetail1("受理时间");
					if (task.getAcceptTime().length() > Config.TIMELENGTH) {
						hd.setDetail1_content(task.getAcceptTime().substring(0,
								Config.TIMELENGTH));
					} else {
						hd.setDetail1_content(task.getAcceptTime());
					}
					historydetaillist.add(hd);*/

					hd = new HistortyDetail();
					hd.setDetail1("报修时间 ");
					if (task.getReportTime().length() > Config.TIMELENGTH) {
						hd.setDetail1_content(task.getReportTime().substring(0,
								Config.TIMELENGTH));
					} else {
						hd.setDetail1_content(task.getReportTime());
					}
					hd.setDetail2("问题描述");
					hd.setDetail2_content(task.getProblemDescript());
					hd.setDetail6("图片留言");
					hd.setDetail6_image1(task.getProblemImage1());
					hd.setDetail6_image2(task.getProblemImage2());
					hd.setDetail6_voice(task.getProblemVoice());
					if (null != task.getProblemVoice()
							&& !task.getProblemVoice().equals("")) {
						int voicetime = Tool.voiceTime(HistorySearchTimeLineActivity.this,Config.VOICE_PATH+task.getProblemVoice());
						int realvoicetime = (int) voicetime/1000;
						
						Log.e("realvoicetime", realvoicetime+"'");
						hd.setDetail6_voicetime(realvoicetime+"'");
					}else{
					}
					historydetaillist.add(hd);
				}
				
				
				timelineAdapter = new TimelineAdapter(
						HistorySearchTimeLineActivity.this, historydetaillist);
				listView.setAdapter(timelineAdapter);
				loginbar.setVisibility(View.INVISIBLE);
				showShortToast((String) msg.obj);
				break;
			case Config.HANDLE_MSG_RFESH_FAIL:
				Toast.makeText(HistorySearchTimeLineActivity.this, (String) msg.obj,
						Toast.LENGTH_SHORT).show();
				break;
			default:
				break;
			}
			super.handleMessage(msg);
		}
	};
	private String functiontitlename;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_history_search_timeline_list);
		initData();
		initViews();
		initEvents();
		loginbar.setVisibility(View.VISIBLE);
		new Thread(getDataRun).start();
	}

	private void initData() {
		user = SingleSample.getInstance(this).getUser();
		intent = getIntent();
		bundle = intent.getExtras();
		repairId = bundle.getString(Config.REPAIRID);
		houseadress = bundle.getString(Config.HOUSE_ADRESS);
		
		areatype = bundle.getString(Config.AREATYPETYPECODE);
		
		functiontitlename = bundle.getString(Config.FUNCTIONTITLENAME);
		repairNodes.clear();
		/*
		 * if(null!=user.getFunctionlistFromUser(Config.
		 * FUNCTION_REAL_HISTORYLIST_OWNER)){//户主 //realfunctioncode =
		 * Config.FUNCTION_REAL_HISTORYLIST_OWNER; }else
		 * if(null!=user.getFunctionlistFromUser
		 * (Config.FUNCTION_REAL_HISTORYLIST_NONOWENER)){//非户主
		 * //realfunctioncode = Config.FUNCTION_REAL_HISTORYLIST_NONOWENER;
		 * }else if(null!=user.getFunctionlistFromUser(Config.
		 * FUNCTION_REAL_HISTORYLIST_DISPATCHER)){//派单员 //realfunctioncode =
		 * Config.FUNCTION_REAL_HISTORYLIST_DISPATCHER; }else
		 * if(null!=user.getFunctionlistFromUser
		 * (Config.FUNCTION_REAL_HISTORYLIST_SERVER)){//服务人员 //realfunctioncode
		 * = Config.FUNCTION_REAL_HISTORYLIST_SERVER; }
		 */
	}

	@Override
	protected void initViews() {
		// TODO Auto-generated method stub
		TextView titleView = (TextView) findViewById(R.id.titlebar_left_center_title);
		titleView.setText(Config.TITLE_HISTORY_DETAIL);
		LinearLayout leftlayout = (LinearLayout) findViewById(R.id.titlebar_left_left_layout);
		leftlayout.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				HistorySearchActivity.HISTORY_REFRESH_FLAG = true;
				finish();
			}
		});
		hdtasknumberTv = (TextView) findViewById(R.id.history_detail_tasknumber);
		hdhouseadressTv = (TextView) findViewById(R.id.history_detail_houseadress);
		hdreporternameTv = (TextView) findViewById(R.id.history_detail_reportername);
		hdreporterphoneTv = (TextView) findViewById(R.id.history_detail_reporterphone);
		hdareaTv = (TextView) findViewById(R.id.history_detail_areatype);
		listView = (ListView) this.findViewById(R.id.history_detail_listview);
		listView.setDividerHeight(0);
		loginbar = (ProgressBar) findViewById(R.id.history_detail_progressBar);

	}

	@Override
	protected void initEvents() {
		// TODO Auto-generated method stub
		// 电话
		hdreporterphoneTv.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
		hdreporterphoneTv.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
		hdreporterphoneTv.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View view) {
				// TODO Auto-generated method stub
				intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:"
						+ hdreporterphoneTv.getText().toString()));
				startActivity(intent);
				finish();
			}
		});
	}

	Runnable getDataRun = new Runnable() {

		@Override
		public void run() {
			// TODO Auto-generated method stub
			getData();

		}
	};

	// 定义发送请求的方法
	private void getData() {
		if (Tool.isNetworkAvailable(HistorySearchTimeLineActivity.this)) {
			try {
				List<Task> tasks;
				String result = null;
				Map<String, String> map = new HashMap<String, String>();				
				String url = Config.SERVER_URL
						+ user.getFunctionlistFromUser(
								Config.FUNCTION_REAL_HISTORY_DETAIL).get(0)
								.getFunctionUrl();
				
				map.put("functionCode", Config.FUNCTION_REAL_HISTORY_DETAIL);
				map.put("repairId", repairId);
				String setsessionid = "";
				User user = SingleSample.getInstance(HistorySearchTimeLineActivity.this).getUser();
				if(null != user){
					if(null != user.getSessionId() && !user.getSessionId().equals("")){
						setsessionid = user.getSessionId();
					}
				}
				result = HttpUtil.postRequestSe(url, map,setsessionid);
				Log.e("历史查询详情的result", result);
				result = result.replace("rows", "tasks");
				String message = new JSONObject(result).getString("message");
				String flag = new JSONObject(result).getString("flag");
				java.lang.reflect.Type type = new TypeToken<User>() {
				}.getType();
				Gson gson = new Gson();
				User u;
				u = gson.fromJson(result, type);
				tasks = u.getTasks();
				for (Task t : tasks) {
					if (t.getRepairId().equals(repairId)) {
						task = t;
						int nodeSize = task.getRepairNodes().size();
						for(int i = 0;i < nodeSize;i++){
							repairNodes.add(task.getRepairNodes().get(nodeSize-i-1));
						}
					}
				}
				if (flag.equals(Config.CONNECT_SUCCESS2)) {
					boolean flagb = false;
					String urlstr = Config.SERVER_URL
							+ user.getFunctionlistFromUser(
									Config.FUNCTION_REAL_DOWNLOADREPAIRFILE)
									.get(0).getFunctionUrl();
					map.put("sessionId", user.getSessionId());
					map.put("functionCode",
							Config.FUNCTION_REAL_DOWNLOADREPAIRFILE);
					if (null != task.getProblemImage1()
							&& !task.getProblemImage1().equals("")) {
						map.put("fileName", task.getProblemImage1());
						flagb = UploadService.downFile(urlstr,
								Config.IMAGE_PATH, map);
					}
					if (null != task.getProblemImage2()
							&& !task.getProblemImage2().equals("")) {
						map.put("fileName", task.getProblemImage2());
						flagb = UploadService.downFile(urlstr,
								Config.IMAGE_PATH, map);
					}
					if (null != task.getProblemVoice()
							&& !task.getProblemVoice().equals("")) {
						map.put("fileName", task.getProblemVoice());
						flagb = UploadService.downFile(urlstr,
								Config.VOICE_PATH, map);
					}
					if (null != task.getSolvedImage1()
							&& !task.getSolvedImage1().equals("")) {
						map.put("fileName", task.getSolvedImage1());
						flagb = UploadService.downFile(urlstr,
								Config.IMAGE_PATH, map);
					}
					if (null != task.getSolvedImage2()
							&& !task.getSolvedImage2().equals("")) {
						map.put("fileName", task.getSolvedImage2());
						flagb = UploadService.downFile(urlstr,
								Config.IMAGE_PATH, map);
					}
					if (null != task.getSolvedVoice()
							&& !task.getSolvedVoice().equals("")) {
						map.put("fileName", task.getSolvedVoice());
						flagb = UploadService.downFile(urlstr,
								Config.VOICE_PATH, map);
					
					}
					if (flagb) {
						mHandler.obtainMessage(
								Config.HANDLER_MSG_GETDATA_SUCCESS, message)
								.sendToTarget();// 通知主线程数据发送成功
					} else {
						mHandler.obtainMessage(
								Config.HANDLER_MSG_GETDATA_SUCCESS, message)
								.sendToTarget();// 通知主线程数据发送成功
					}
				} else {
					mHandler.obtainMessage(Config.HANDLER_MSG_GETDATA_SUCCESS,
							message).sendToTarget();// 通知主线程数据发送成功
				}

			} catch (Exception e) {
				Log.e("ServiceScheduleActivity", "json数据获取报错");
				/*
				 * Toast.makeText(getActivity(), "网络连接出错" ,
				 * Toast.LENGTH_SHORT).show();
				 */
				e.printStackTrace();
			}

		} else {
			/* start = ++refreshCnt; */
			mHandler.obtainMessage(Config.HANDLE_MSG_RFESH_FAIL,
					"请设置网络").sendToTarget();// 网络中断
		}
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) { // 监控/拦截/屏蔽返回键
			HistorySearchActivity.HISTORY_REFRESH_FLAG = true;
			finish();
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}
}
